package com.spacewiz13.algorithm.number;

import java.util.Stack;

/**
 * 反转数字。
 * Example1: x = 123, return 321
Example2: x = -123, return -321
 * @author David
 *
 */
public class ReverseNumber {

	
	public static void main(String[] args){
		System.out.println(reverse(1534236469));
	}
	
    public static int reverse(int x) {
    	int result = 0;
        while(x!=0){
        	if(Math.abs(result)>Integer.MAX_VALUE/10)
        		return 0;
        	int lastNumber = x%10;
        	x = x/10;
        	result = result*10+lastNumber;
        }

        return result;
    }
}
